<?php
 class SearchAction extends Action{
 	public function bysid(){
 		$sid=$_POST["getsid"];
 		if (empty($sid)||$sid==0) {
 			echo $this->fetch();
 			exit();
 		}
 		$s=D("Search");
		$data=$s->getOnedetail($sid,"base");
		$data[0]["class"]=$s->getClass($data[0]["major"],$data[0]["class"]);
		$data[0]["major"]=$s->getMajor($data[0]["major"]);
		if ((int)$data[0]["isparty"]==1) {
			$data[0]["isparty"]="党员";
		}else if((int)$data[0]["isparty"]==2){
			$data[0]["isparty"]="团员";
		}else{
			$data[0]["isparty"]="群众";
		}
		$this->assign("oneDetail",$data[0]);
		echo $this->fetch("Page:searchbydetail");
 	} 
 	
 	public function byname(){
 		$name=$_POST["getname"];
 		if(empty($name)) {
 			echo $this->fetch();
 			exit();
 		}
 		$s=D("Search");
 		$where["name"]=array("like","%".$name."%");
 		$search=M("Baseinfo");;
 		$list=$search->where($where)->field("sid,name,sex,grade,major,class")->select();
 		$count=count($list);
 		for ($i=0;$i<$count;$i++){
 			$list[$i]["class"]=$s->getClass($list[$i]["major"],$list[$i]["class"]);
 			$list[$i]["major"]=$s->getMajor($list[$i]["major"]);
 			
 		}
 		$this->assign("list",$list);
 		echo $this->fetch("Page:searchbyname");
 	}
 	
 	public function byclass(){
 		$grade=$_POST["getgrade"];
 		$major=$_POST["getmajor"];
 		$class=$_POST["getclass"];
 		if (empty($grade)||empty($major)||empty($class)) {
 			echo $this->fetch();
 			exit();
 		}
 		$search=D("Search");
 		$list=$search->getClassMemberList((int)$grade,(int)$major,(int)$class);
 		$this->assign("class",$list);
 		echo $this->fetch("Page:searchbyclass");
 		
 	}
 	
 	public function byidcard(){
 		$idcard=$_POST["getidcard"];
 		if (empty($idcard)) {
 			echo $this->fetch();
 			exit();
 		}
 		$s=D("Search");
 		$where["idcard"]=$idcard;
 		$search=M("Baseinfo");;
 		$data=$search->where($where)->field("password",true)->limit(1)->select();
 		$data[0]["class"]=$s->getClass($data[0]["major"],$data[0]["class"]);
		$data[0]["major"]=$s->getMajor($data[0]["major"]);
		if ((int)$data[0]["isparty"]==1) {
			$data[0]["isparty"]="党员";
		}else if((int)$data[0]["isparty"]==2){
			$data[0]["isparty"]="团员";
		}else{
			$data[0]["isparty"]="群众";
		}
 		$this->assign("oneDetail",$data[0]);
 		echo $this->fetch("Page:searchbydetail");
 	}
 	
 	public function byby(){
 		$year=$_POST["getby"];
 		$major=$_POST["getmajor"];
 		$class=$_POST["getclass"];
 		if (empty($year)||empty($major)||empty($class)) {
 			echo $this->fetch();
 			exit();
 		}
 		$base=M("Baseinfo");
 		$where["isby"]=$year;
 		$where["major"]=$major;
 		$where["class"]=$class;
 		$stList=$base->where($where)->field("sid,name")->select();
 		$by=M("Graduate");
 		$people=count($stList);
 		for ($i=0;$i<$people;$i++){
 			$list[$i]["sid"]=$stList[$i]["sid"];
 			$list[$i]["name"]=$stList[$i]["name"];
 			$list[$i]["workplace"]=$by->where("sid=".$list[$i]["sid"])->getField("workplace");
 			$list[$i]["job"]=$by->where("sid=".$list[$i]["sid"])->getField("job");
 			$list[$i]["address"]=$by->where("sid=".$list[$i]["sid"])->getField("address");
 			$list[$i]["phone"]=$by->where("sid=".$list[$i]["sid"])->getField("phone");
 		}
 		$this->assign("bylist",$list);
 		echo $this->fetch("Page:searchbyby");
 	} 
 }
?>